package com.qianfeng.recyclerdemo02.utils;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
/**
 * 加载图片的异步任务工具类。
 * */
public class ImageAsyncTask extends AsyncTask<String, Void, Bitmap>{

	private Context context;
	private ImageCallback callback;
	private String path;
	private int sampleSize;
	public ImageAsyncTask(Context context, ImageCallback callback,int sampleSize) {
		super();
		this.context = context;
		this.callback = callback;
		this.sampleSize = sampleSize;
	}

	@Override
	protected Bitmap doInBackground(String... params) {
		path = params[0];
		byte[]data =  HttpUtils.getByteContent(params[0]);
		
		return BitmapUtils.getScaleBitmap(data, sampleSize);
	}
	
	@Override
	protected void onPostExecute(Bitmap result) {
		super.onPostExecute(result);
		callback.sendImage(result, path);
		
		
	}

	public interface ImageCallback{
		public void sendImage(Bitmap bm, String path);
	}
}
